package com.hzdl.secondweektest.test01;

import java.util.Scanner;

/**
 * 属性：帐号、姓名、地址、存款余额、最小余额，应声明为私有；
 * 方法：存款、取款、查询账户信息
 */
public class Account {
    private String account;
    private String name;
    private String address;
    private double bankBalance;
    private double minBalance = 50.0;

    public Account() {
    }

    public Account(String account, String name, String address, double bankBalance, double minBalance) {
        this.account = account;
        this.name = name;
        this.address = address;
        this.bankBalance = bankBalance;
        this.minBalance = minBalance;
    }

    public Account(String account, String name, String address) {
        this.account = account;
        this.name = name;
        this.address = address;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public double getBankBalance() {
        return bankBalance;
    }

    public void setBankBalance(double bankBalance) {
        this.bankBalance = bankBalance;
    }

    public double getMinBalance() {
        return minBalance;
    }

    public void setMinBalance(double minBalance) {
        this.minBalance = minBalance;
    }

    @Override
    public String toString() {
        return "Account{" +
                "account='" + account + '\'' +
                ", name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", bankBalance=" + bankBalance +
                ", minBalance=" + minBalance +
                '}';
    }

    //存款方法
    public void saveMoney( double money) {
        if (money < 100.0) {
            System.out.println("第一次存款金额不得少于100!");
        }
        System.out.println("原有余额：" + this.getBankBalance());
        System.out.println("存入金额：" + money);
        System.out.println("最终金额：" + (money + this.getBankBalance()));

    }

    //取款方法
    public void getMoney(double get) {
        System.out.println("是否需要取款？y/n");
        String key = new Scanner(System.in).next();
        if ("y".equalsIgnoreCase(key)){
            if (this.getMinBalance() < 50.0){
                System.err.println("您的最小余额不足50,拒绝取款");
            }else {
                this.setBankBalance(this.getBankBalance()-get);
                System.out.println("您已经取出"+get);
                System.out.println("您的银行余额为："+this.getBankBalance());
            }

        }
    }

    //查询账户信息
    public void find() {
        System.out.println(this.toString());
    }
}
